# Maintainer: Bart Ribbers <bribbers@disroot.org>

# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=qt6
pkgname=qt6-qttools
pkgver=6.7.2
pkgrel=0
_llvmver=18
pkgdesc="A cross-platform application and UI framework (Development Tools, QtHelp)"
url="https://qt.io/"
arch="all"
license="LGPL-2.1-only AND LGPL-3.0-only AND GPL-3.0-only AND Qt-GPL-exception-1.0"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	qt6-qtdeclarative-dev
	vulkan-headers
	"
# -static not used but needed for cmake
makedepends="$depends_dev
	clang$_llvmver-dev
	clang$_llvmver-static
	clang$_llvmver-extra-tools
	cmake
	llvm$_llvmver-dev
	llvm$_llvmver-gtest
	llvm$_llvmver-static
	perl
	samurai
	"
checkdepends="xvfb-run"
subpackages="$pkgname-dev $pkgname-libs"
builddir="$srcdir/qttools-everywhere-src-${pkgver/_/-}"

case $pkgver in
	*_alpha*|*_beta*|*_rc*) _rel=development_releases;;
	*) _rel=official_releases;;
esac

source="https://download.qt.io/$_rel/qt/${pkgver%.*}/${pkgver/_/-}/submodules/qttools-everywhere-src-${pkgver/_/-}.tar.xz"
options="!check" # Tests aren't found

build() {
	# their cmake uses the clang_include_dirs only, but our llvm include dirs
	# are in another castle
	export CXXFLAGS="$CXXFLAGS -flto=auto -U_FORTIFY_SOURCE -I/usr/include/llvm$_llvmver"
	export CFLAGS="$CFLAGS -flto=auto"
	export PATH="/usr/lib/llvm$_llvmver/bin:$PATH"
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DINSTALL_PUBLICBINDIR=usr/bin
	cmake --build build
}

check() {
	xvfb-run ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	cd "$pkgdir"
	mkdir -p usr/bin

	while read -r line; do
		ln -s $line
	done < "$builddir"/build/user_facing_tool_links.txt
}

sha512sums="
311467d0e6970711b4d984fe792d2b75609f38c04121073d5c3c34c682fcee89787f6982c886e62206a76b1f647de60e56510439b0288f8bd1ae21a2683a37cd  qttools-everywhere-src-6.7.2.tar.xz
"
